<template>
    <view class="content">
        <van-popup position="bottom" @click-overlay="closePopup" :show="show" round z-index=104
            custom-style="width: 100%;background:#ffffff;overflow: hidden; ">
            <view class="popup-content">
                <scroll-view :refresher-enabled="false" class="scroll-content" scroll-y :lower-threshold="80"  show-scrollbar="false">

                <view class="popup-main">
                <view style="display: flex; justify-content: space-between;">
                    <view class="popupTitle"> {{title}}</view>
                    <van-icon name="cross"  size="15" @click="closePopup" />
                </view>
                    <!-- 服务信息 -->
                <view class="serviceInfo">
                    <view class="serviceInfoContent">
                        <view class="serviceInfoLabel">服务项目： <span>{{serviceInfo.storeName}}{{serviceInfo.newName}}</span></view>
                        <view class="serviceInfoLabel">预约时长： <span>{{serviceInfo.hour}}小时</span></view>
                        <view class="serviceInfoLabel">服务时间： <span>{{serviceInfo.reservationTime}}</span></view>
                        <view class="serviceInfoLabel">预约地址： <span>{{serviceInfo.addressDetail}}{{serviceInfo.houseNumber}}</span></view>
                    </view>
                </view>
                <!-- 服务人员 Service Staff-->
                <!-- <view class="serviceStaffInfo">
                    <view class="serviceStaffInfoTitle">服务人员</view>
                    <view class="serviceStaffInfoContent">
                        <view class="serviceStaffImg"><img src="https://17lelife-bucket.oss-cn-beijing.aliyuncs.com/WeChat-App-Picture/my/info.png"  alt="" mode="widthFix"></view>
                        <view class="serviceStaffText">
                            <view class="staffName">刘甜甜 <span>8年工作经验</span></view>
                            <view class="staffInfoLabel">
                                <view class="labelItem"  v-for="(item,index) in labelList" :key="index" :class="index===0 ? 'labelItem' : (index===1 ? 'blueItem' : (index==2 ? 'greenItem':'') )">
                                    {{item}}
                                </view>
                            </view>
                        </view>
                        <view class="serviceInfoTel" > <van-icon name="phone" siza="22"/> </view>
                    </view>
                </view> -->
                </view>
                </scroll-view>

                <!-- <view class="goodsAction nav_box">
                    <van-goods-action>
                        <van-goods-action-button color="#FF6203" text="开始服务" @click="startService"  :disabled="isSubmitting"
                        :class="{ 'disabled-btn': isSubmitting }"/>
                    </van-goods-action> -->
                    <!-- <view class="cancelTips">
                        如行程有变，需至少提前N天/时间进行取消，否则将会扣除对应违约责次数，每个用户限免N次 <span @tap="toAgreement">《取消预约协议》</span>
                    </view> -->
                <!-- </view> -->
                <view class="btn-area">
                    <van-button type="primary" class="" @click="startService" :disabled="isSubmitting"
                        :class="{ 'disabled-btn': isSubmitting }">开始服务</van-button>
                </view>
            </view>
        </van-popup>
    </view>
</template>

<script>
import Toast from '@/wxcomponents/vant/toast/toast'
import {startServiceApi} from '@/api/staff'
export default {
    props: {
        show: {
            type: Boolean,
            default: () => false
        },
        popupParams: {
            type: Object,
            default: () => ({})
        }
    },
    data () {
        return {
            curS:0,
            curSName:'',
            date: '',
            showMark: true, // 标记
            title: '开始服务',
            option: {},
            serviceInfo:{
                id:1,
                newName:'信合名都社区水岸华庭东郡亲子活动游戏活动',
                hour:'3小时',
                houseNumber:'黄金水岸3号楼1单元201',
                reservationTime:'2025-02-19 14:00-16:00'
            },
            isSubmitting: false,
            submitTimer: null    // 防抖定时器


        }
    },

    computed: {
    },


  watch:{
    popupParams: {
    
        handler(newVal) {
            this.serviceInfo = newVal.apiData
            console.log(this.serviceInfo)
        },
        deep: true
    }
  },
    onLoad () {
        if (this.house===0) {
            // this.title = '商品排序'
        } else{
            // this.title = '全部分类'
        }
      
    },
    onReady () { },

    methods: {
  
        // 关闭弹窗
        closePopup () {
            console.log('关闭 关闭关闭---------')
            this.$emit('closeEnterlPopup')
        },
        // 开始服务
        async startService() {
            if (this.isSubmitting) return;
            this.isSubmitting = true;
            clearTimeout(this.submitTimer);
            this.submitTimer = setTimeout(async () => {
                try {
                    const res = await startServiceApi({
                        reservationId: this.popupParams.reservationId,
                        versionNo: this.popupParams.versionNo,
                    })
                    if (res.code === 200) {
                        this.closePopup() // 关闭弹窗
                        this.$emit('startService') // 触发父组件的事件
                    }else{
                        this.closePopup() // 关闭弹窗
                    }
                   
                } catch (error) {
                    console.error('取消失败:', error);
                    Toast('取消失败，请重试');
                } finally {
                    this.isSubmitting = false;
                    clearTimeout(this.submitTimer);
                }
            }, 500); // 500ms防抖间隔
        }


  },

}
</script>
<style lang="scss" scoped>

::v-deep .van-button__text {
    display: flex !important;
    flex-direction: column !important;
}
// 提示框
.popup-content {
    padding:24px;
    font-size: 12px;
    background: #ffffff;
    border-radius: 16px;
    overflow: hidden;
    // height: 50%;


    .popup-main {
        // height: 100%
        height:calc(100% - (144rpx + env(safe-area-inset-bottom)));
        padding-bottom: calc(144rpx + env(safe-area-inset-bottom));
    }


    .popupTitle {
        font-size: 20px;
        text-align: left;
        color: #111111;
        line-height: 20px;
    }

}

// 服务信息
.serviceInfo{
    margin-top:48rpx;
    // padding:0rpx 48rpx;
    // border-bottom: 2rpx solid #f0f0f0;
    .serviceInfoTitle{
        font-size: 38rpx;
        text-align: left;
        color: #111111;
        line-height: 38rpx;
    }
    .serviceInfoContent{
        margin-top: 52rpx;
        padding-bottom: 49rpx;
        .serviceInfoLabel{
            font-size: 32rpx;
            line-height: 32rpx;
            text-align: left;
            color: #999999;
            margin-bottom:24rpx;
            display: flex;
            align-items: center;
            width: 100%;

            span{
                width: 60%;
                font-size: 32rpx;
                text-align: left;
                color: #333333;
                line-height: 32rpx;
                white-space: nowrap;
                /* 防止文本换行 */
                overflow: hidden;
                /* 超出部分隐藏 */
                text-overflow: ellipsis;
                /* 显示省略号 */
            }
        }
    }
}
// 服务人员
.serviceStaffInfo{
    // padding:0rpx 48rpx;

    .serviceStaffInfoTitle{
        font-size: 38rpx;
        text-align: left;
        color: #111111;
        line-height: 38rpx;
    }
    .serviceStaffInfoContent{
        padding-top: 52rpx;
        padding-bottom: 62rpx;
        display: flex;


        .serviceStaffImg{
            width: 15%;
            display: flex;
            flex-direction: column;
            justify-content: center;

            img{
                width: 100%;
                height: auto;
            }
        }
        .serviceStaffText{
            margin-left: 44rpx;
            .staffName{
                font-weight: bolder;
                font-size: 38rpx;
                text-align: left;
                color: #111111;
                line-height: 38rpx; 
                display: flex;
                align-items: center;

                span{
                    font-weight: normal;
                    font-size: 26rpx;
                    text-align: left;
                    color: #111111;
                    line-height: 26rpx;
                    padding-left:20rpx;
                }
            }
            .staffInfoLabel{
                display: flex;
                margin-top: 18rpx;

                .labelItem{
                    border: 1px solid #FF6203;
                    background-color: #FFF4ED;
                    color: #FF6203;
                    font-size: 20rpx;
                    line-height: 20rpx;
                    text-align: center;
                    padding: 10rpx 22rpx;
                    // border-radius: 25rpx;
                    margin-right: 16rpx;
                }
                // .blueItem{
                //     border: 1px solid #0094D9;
                //     background-color: rgb(0, 148, 217, 0.06);
                //     color: #0094D9;
                // }
                // .greenItem{
                //     border: 1px solid #00CB00;
                //     background-color: rgb(0, 203, 0, 0.06);
                //     color: #00CB00;
                // }
                .labelItem:last-child{
                    margin-right: 0rpx;
                }
            }
        }
        .serviceInfoTel{
            text-align: right;
            margin-left: 60rpx;
        }

    }
}

// 去绑定的按钮
.button{
    // width: 100%;
    font-size: 12px;
    color: #ffffff;
    height: 20px;
    line-height:20px;
    border-radius: 10px;
    border-style: initial !important;
    padding: 0 11px !important;
    background: #FF6203 !important;
    margin-left: 13px;
}
.cancelTips{
    margin-top: 32rpx;
    color: #999999;
    font-size: 20rpx;
    
    span{
        color: #FF6203;
    }
}

.goodsAction {
    position: relative;
    
    .cancelTips {
        margin-top: 32rpx;
        color: #999999;
        font-size: 20rpx;
        padding: 0 24rpx;  // 添加左右边距
        line-height: 1.5;  // 增加行高
        transform: translateY(-60rpx); // 上移位置
        
        span {
            color: #FF6203;
            display: inline-block; // 使协议文字可点击
            margin-top: 16rpx;
        }
    }
    
    // 调整按钮容器高度
    ::v-deep .van-goods-action {
        height: auto !important;
        padding-bottom: 40rpx;
    }
}
::v-deep .van-button--primary {
  width: 100%;
  height: 86rpx;
  border-radius: 50rpx;
  background: #ff6203;
  margin-top: 32rpx;
  font-size: 28rpx;
}
.disabled-btn {
    // background-color: #cccccc !important;
    border-color: #cccccc !important;
}
</style>

